#ifndef SG_QUANTIZE96_H_INCLUDED
#define SG_QUANTIZE96_H_INCLUDED

#include <stdint.h>
#include "rand.h"

#ifdef __cplusplus
extern "C" {
#endif

struct quantize96_state
{
	struct randctx prng_state;
	int_least32_t memory[4];
	int_least32_t last_err;
};

/**
 * initializes the state struct
 */
extern void quantize96_init(struct quantize96_state *s);

/**
 * scales and quantizes 16-bit samples using a noise shaping filter
 * that is optimized for a sampling frequency of 96 kHz (or above).
 *
 * The scaling works like this:
 *   out[k] = (in[k] * scale) >> shift;
 * So, for an 8 bit output you would set scale=1 and shift=8.
 * Of course, the above code is just a simplification because it does
 * not show how noise shaping is done.
 *
 * Note: in-place transformation (in==out) is supported.
 *
 * @param s
 *   pointer to quantizer state
 * @param scale
 *   scale factor
 * @param shift
 *   amount of bits to shift right
 * @param num_samples
 *   amount of samples to process
 * @param in
 *   pointer to input samples
 * @param out
 *   pointer to output samples
 */
extern void quantize96_process(
	struct quantize96_state *s,
	int scale, int shift,
	int num_samples_in,
	const int16_t in[],
	int16_t out[]);

#ifdef __cplusplus
}
#endif

#endif
